<!--联系人设置-->
<template>
  <div class="contain">
    <div class="form-switch mt30">
      <x-switch :title="name" :value="true" v-model="switchV.sh" @on-change="checked"></x-switch>
    </div>
    <h2 class="form-tit-row">开通权限</h2>
    <div class="form-switch mb30">
      <x-switch title="预约发货" :value="false" v-model="switchV.fh"></x-switch>
    </div>
    <div class="form-switch mb30">
      <x-switch title="预约调度" :value="false" v-model="switchV.dd"></x-switch>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      switchV:{
        sh:true,
        fh:false,
        dd:false
      },
      id:'',
      name:'',
      ishide:'',
      RoleName:'',
      typename:''
    }
  },
  // watch: {
  //   'switchV.sh': function(newV) {
  //     if (newV) {
  //        this.addrole('Y');
  //     }else{
  //       this.addrole('N');
  //     }
  //   },
  // },
  created() {
    this.id =this.$route.query.id;
    this.name=this.$route.query.name;
    this.typename=this.$route.query.typename;
    this.ishide= this.$route.query.IsHide;
    this.RoleName= this.$route.query.RoleName;
    console.log(this.RoleName);
    if (this.ishide) {
      this.switchV.sh=true;
    }else{
      this.switchV.sh=false;
    }
  },
  mounted() {
    this.$nextTick(function() {
      
    })
  },
  methods: {
    addrole(type){
      var self =this;
      var userinfo = JSON.parse(localStorage.userinfo);
      var query = {
          TenantGuid: userinfo.TenantGUID,
          RoleName: this.RoleName,
          CorpGuid: userinfo.CorpGuid,
          Isdelete: type,
          PageID:this.id,
          CreateUserId:userinfo.StaffID,
          CreateUserName:userinfo.Name,
      };
      this.Ajax.post('CreateMFPlatFormRole', query).then(function(resp) {
         if (resp.IsSuccess) {
             self.$router.push({
              path: "/user/power",
              query:{type:self.RoleName,name:self.typename},
            });
         }else{
             self.Toast({
                message: '操作失败！'
            });
         }
      });
    },
    checked (value) {
      if (value) {
          this.MessageBox.confirm('是否开启该功能').then(action => {
            this.addrole('Y');
          });
        
      }else{
         this.MessageBox.confirm('是否禁用该功能').then(action => {
            this.addrole('N');
          });
       
      }
    },
  }
}
</script>